package mortal.game.control
{
    import modules.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class OfflineExpController extends Controller
    {
        private var _time:int;
        private var _exp:int;

        public function OfflineExpController()
        {
            
        }

        override protected function initView() : IView
        {
            var _loc_1:* = new OfflineExpModule();
            return _loc_1;
        }

        override protected function initServer() : void
        {
            Dispatcher.addEventListener(EventName.LoginGameSuccess, this.onLoginGameSuccessHandler);
            Dispatcher.addEventListener(EventName.GetOfflineExp, this.onGetOfflineExpHandler);
            NetDispatcher.addCmdListener(ServerCommand.GetOfflineTimeSuccess, this.onGetTimeSuccessHandler);
            Dispatcher.addEventListener(EventName.OfflineExpPropUse, this.onOfflineExpPropUseHandler);
            NetDispatcher.addCmdListener(ServerCommand.BackPackItemsChange, this.onBackPackChangeHandler);
            
        }

        private function onLoginGameSuccessHandler(event:DataEvent) : void
        {
            GameProxy.offlineExpProxy.getOfflineTime();
            
        }

        private function onGetOfflineExpHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data;
            GameProxy.offlineExpProxy.gainOfflineExp(_loc_2.type, _loc_2.time);
            
        }

        private function onGetTimeSuccessHandler(param1:Object) : void
        {
            var _loc_2:* = param1.time as int;
            var _loc_3:* = param1.exp as Number;
            this._time = _loc_2;
            this._exp = _loc_3;
            if (_loc_2 > 0 || _loc_3 > 0)
            {
                view.show();
                (view as OfflineExpModule).setData(_loc_2, _loc_3);
            }
            else if (!view.isHide)
            {
                (view as OfflineExpModule).setData(_loc_2, _loc_3);
                view.hide();
            }
            
        }

        private function onOfflineExpPropUseHandler(event:DataEvent) : void
        {
            if (this._time >= 1)
            {
                if (!view.isHide)
                {
                    
                }
                view.show();
                (view as OfflineExpModule).setData(this._time, this._exp);
            }
            else
            {
                MsgManager.addBroadCast("您当前没有可以领取的离线经验");
            }
            
        }

        private function onBackPackChangeHandler(param1:Object) : void
        {
            if (!view.isHide)
            {
                (view as OfflineExpModule).backPackChange();
            }
            
        }

    }
}
